package cn.seven._conf._filter;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * create by 张天笑, 2017/10/26 13:19
 */
@Component
@WebFilter(urlPatterns = "/*", filterName = "globalFilter")
public class GlobalFilter implements Filter {
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("GlobalFilter---------------cn.seven._conf._filte.GlobalFilter");
    	Cookie[] cookies = ((HttpServletRequest) servletRequest).getCookies();
        if (cookies != null && cookies.length > 0) {
            int maxAge = cookies[0].getMaxAge();
        }
        try {
            filterChain.doFilter(servletRequest, servletResponse);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    public void destroy() {

    }
}
